﻿Imports System.Data.OleDb

Public Class AddRecipe
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newPhotoName = myGUID.ToString() + ".jpg"


        If f_Photo.HasFile Then
            f_Photo.SaveAs(Request.MapPath("~/Pictures") & "/" & newPhotoName)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionStringRestaurants").ConnectionString)
        Dim SqlString As String = "Insert into Recipes(Title,FullRecipe,Photo,UserName) Values (@f1,@f2,@f3,@f4)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_Title.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Recipe.Text)
        cmd.Parameters.AddWithValue("@f3", "~/Pictures/" & newPhotoName)
        cmd.Parameters.AddWithValue("@f4", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("~/confirmation.aspx")

    End Sub
End Class